package com.bonc.service.impl;

import com.bonc.entity.ParkCompany;
import com.bonc.mapper.ParkCompanyMapper;
import com.bonc.service.ParkCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 努力！奋斗！
 * 理解的快不等于理解的好！
 *
 * @author LRJ
 * @Date 2021/08/02  8:50
 **/
@Service
public class ParkCompanyServiceImpl implements ParkCompanyService {

    @Autowired
    private ParkCompanyMapper parkCompanyMapper;

    /**
     * 高级查询并且分页
     * @param parkCompany
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<ParkCompany> queryParCompany(ParkCompany parkCompany,
                                             Integer pageNum, Integer pageSize) {

        pageNum = (pageNum -1) * pageSize;
        if (pageNum < 0){
            pageNum = 0;
        }
        return parkCompanyMapper.queryParCompany(parkCompany, pageNum, pageSize);
    }

    /**
     * 查看详情(根据id查询数据)
     *
     * @param id
     * @return
     */
    @Override
    public ParkCompany findById(String id) {
        return parkCompanyMapper.findById(id);
    }

    /**
     * 获取企业新增数目或者增长率
     *
     * @param year 年份
     * @param rate 是否取得增长率(其他是增长率  1是新增数量)
     * @return
     */
    @Override
    public Double getGrowthRate(Integer year, Integer rate) {
        if (0 == year){
            SimpleDateFormat slf = new SimpleDateFormat("yyyy");
            String format = slf.format(new Date());
            year = new Integer(format);
        }
        if (rate == 1) {
            return (double)parkCompanyMapper.getGrowthRate(year, rate) - parkCompanyMapper.getGrowthRate((year - 1), rate);
        } else {
            Double growthRate = (double)(parkCompanyMapper.getGrowthRate(year, rate) - parkCompanyMapper.getGrowthRate((year - 1), rate)) / parkCompanyMapper.getGrowthRate((year - 1), rate);
            return (double) Math.round(growthRate * 100);
        }
    }

    @Override
    public List<Map<String,Object>> findComponyIncreaseRate(){

        List<Map<String,Object>> list=parkCompanyMapper.findComponyIncreaseRate();
        return list;
    }
    @Override
    public List<Map<String,String>> findRegisteredCapital() {

        return parkCompanyMapper.findRegisteredCapital();
    }


}
